<?php
	// The Class will provide functionality for retrieving events, event categories, and information associated with events such as instructors 
	class getEvents extends WebService_base{
		/**
		 * Constructor  */
		function __construct(){
			parent::__construct();
		}
		/**
		 * Call returnALL for an array containing strings: one, two, Three. 
		* @return mixed **/
		function returnAll(){
			$myvar = array("one", "two", "Three");
			return 	$myvar;
		}
		/**
		 * Return a list of all events by category
		 *
		 * @return mixed
		 */
		function listEvents(){
			$events = array();
			$link = $this->db_connect();
			if ($link){ 
				$getEvents['nameID'] ="SELECT events_name, events_id FROM events_description";
				$getEvents['category'] ="SELECT a.events_categories_name, a.events_categories_heading_title, a.events_categories_description, b.events_categories_id FROM events_categories_description a, events_categories b WHERE a.events_categories_id = b.events_categories_id";
				$getEvents['fullDetails'] = "SELECT 	";
					$getEvents['fullDetails'] .= "a.events_categories_name, a.events_categories_heading_title, a.events_categories_description, "; 
					$getEvents['fullDetails'] .= "b.events_categories_id, ";
					$getEvents['fullDetails'] .= "c.events_name, c.events_id, c.events_description, c.events_teaser_text, ";
					$getEvents['fullDetails'] .= "e.events_status, e.events_fees, e.events_start_time, e.events_end_time, ";
					$getEvents['fullDetails'] .= "f.location_name, f.location_seats, f.location_details, ";
					$getEvents['fullDetails'] .= "g.sessions_id ";
				$getEvents['fullDetails'] .= "FROM ";
					$getEvents['fullDetails'] .= TABLE_EVENTS_CATEGORIES_DESCRIPTION . " a, ";
					$getEvents['fullDetails'] .= TABLE_EVENTS_CATEGORIES . " b, ";
					$getEvents['fullDetails'] .= TABLE_EVENTS_DESCRIPTION . " c, ";
					$getEvents['fullDetails'] .= TABLE_EVENTS_TO_EVENTS_CATEGORIES . " d, ";
					$getEvents['fullDetails'] .= TABLE_EVENTS ." e, ";
					$getEvents['fullDetails'] .= TABLE_EVENTS_LOCATIONS . " f, ";
					$getEvents['fullDetails'] .= TABLE_EVENTS_SESSIONS . " g ";
				$getEvents['fullDetails'] .= "WHERE ";
					$getEvents['fullDetails'] .= "e.events_status = 1 ";	
					$getEvents['fullDetails'] .= "AND d.events_id = e.events_id ";
					$getEvents['fullDetails'] .= "AND e.events_id = g.events_id ";
					$getEvents['fullDetails'] .= "AND d.events_categories_id = b.events_categories_id ";
					$getEvents['fullDetails'] .= "AND a.events_categories_id = b.events_categories_id ";
					$getEvents['fullDetails'] .= "AND	c.events_id = d.events_id ";
					$getEvents['fullDetails'] .= "AND 	b.events_categories_id = d.events_categories_id ";
					$getEvents['fullDetails'] .= "AND	f.location_id = e.events_location ";
//					$getEvents['fullDetails'] .= "GROUP BY 	b.events_categories_id, c.events_id";
					$getEvents['fullDetails'] .= "GROUP BY 	c.events_id";
			}
			else
				return array("Failed to Connect to Database", mysql_error($link));

			foreach($getEvents as $name => $query){
				$ge_results[$name] = $this->db_query($query, $link);
				$ge_errors[$name.'_error'] = mysql_error($link); 
			}
			foreach($ge_results as $name => $cur_result){
				$$name = array();
				if($cur_result){
					if($this->db_num_rows($cur_result)>0){
						while($row = mysql_fetch_assoc($cur_result)){
							array_push($$name, $row);
						}
					}
					//array_push($events, $$name);
					$events[$name] = $$name;
				}
				else
					return array("Query, $name, failed to Produce Results:  " . $ge_errors[$name.'_error']);
			}					
			return $events;
		}
	}

	
?>
